﻿@using PagedList; <!-- import this so we can cast our list to IPagedList (only necessary because ViewBag is dynamic) -->
@using PagedList.Mvc; <!-- import this so we get our HTML Helper -->
@model IEnumerable<PhoneStoreWeb.Models.Product>

<link href="~/Content/Tooltipster.css" rel="stylesheet" type="text/css" />
<script src="~/Scripts/jquery.tooltipster.min.js" type="text/javascript"></script>

<script type="text/javascript">
    $(document).ready(function() {
        $('.tooltip').tooltipster({
            animation: 'grow',
            fixedWidth: 300,
            maxWidth: 500,
            position: 'left'
        });
    });
</script>

@foreach (var item in Model)
{
    <div id="product">
        @{
            string imageContent = "<div class='tooltip-title'>Tính năng nổi bật:</div><div class='tooltip-content'>";
            if (item.IsHighlighted)
            {
                if (item.PhoneTablet.IsGeneralHighlighted)
                {
                    imageContent += "- Mạng 4G: " + item.PhoneTablet.Phone_General.FourGNetwork + "<br />";
                    imageContent += "- SIM: " + item.PhoneTablet.Phone_General.Sim + "<br />";
                }
                if (item.PhoneTablet.IsBodyHighlighted)
                {
                    imageContent += "- Kích thước: " + item.PhoneTablet.Phone_Body.Dimensions + "<br />";
                    imageContent += "- Trọng lượng: " + item.PhoneTablet.Phone_Body.Weight + "<br />";
                }
                if (item.PhoneTablet.IsDisplayHighlighted)
                {
                    imageContent += "- Loại: " + item.PhoneTablet.Phone_Display.Type + "<br />";
                    imageContent += "- Kích thước: " + item.PhoneTablet.Phone_Display.Size + "<br />";
                    imageContent += "- Cảm ứng đa điểm: " + item.PhoneTablet.Phone_Display.Multitouch + "<br />";
                    imageContent += "- Chế độ bảo vệ: " + item.PhoneTablet.Phone_Display.Protection + "<br />";
                }
                if (item.PhoneTablet.IsSoundHighlighted)
                {
                    imageContent += "- Loại cảnh báo: " + item.PhoneTablet.Phone_Sound.AlertTypes + "<br />";
                }
                if (item.PhoneTablet.IsMemoryHighlighted)
                {
                    imageContent += "- Khe cắm: " + item.PhoneTablet.Phone_Memory.CardSlot + "<br />";
                    imageContent += "- Bộ nhớ trong: " + item.PhoneTablet.Phone_Memory.Internal + "<br />";
                }
                if (item.PhoneTablet.IsDataHighlighted)
                {
                    imageContent += "- GPRS: " + item.PhoneTablet.Phone_Data.GPRS + "<br />";
                    imageContent += "- EDGE: " + item.PhoneTablet.Phone_Data.EDGE + "<br />";
                    imageContent += "- Tốc độ mạng: " + item.PhoneTablet.Phone_Data.Speed + "<br />";
                    imageContent += "- Wifi: " + item.PhoneTablet.Phone_Data.WLAN + "<br />";
                    imageContent += "- Bluetooth: " + item.PhoneTablet.Phone_Data.Bluetooth + "<br />";
                    imageContent += "- NFC: " + item.PhoneTablet.Phone_Data.NFC + "<br />";
                    imageContent += "- Hồng ngoại: " + item.PhoneTablet.Phone_Data.InfraredPort + "<br />";
                    imageContent += "- USB: " + item.PhoneTablet.Phone_Data.USB + "<br />";
                }
                if (item.PhoneTablet.IsCameraHighlighted)
                {
                    imageContent += "- Camera chính: " + item.PhoneTablet.Phone_Camera.PrimaryCamera + "<br />";
                    imageContent += "- Đặc tính: " + item.PhoneTablet.Phone_Camera.Features + "<br />";
                    imageContent += "- Video: " + item.PhoneTablet.Phone_Camera.Video + "<br />";
                    imageContent += "- Camera phụ: " + item.PhoneTablet.Phone_Camera.SecondaryCamera + "<br />";
                }
                if (item.PhoneTablet.IsFeaturesHighlighted)
                {
                    imageContent += "- Hệ điều hành: " + item.PhoneTablet.Phone_Features.OS + "<br />";
                    imageContent += "- Chipset: " + item.PhoneTablet.Phone_Features.Chipset + "<br />";
                    imageContent += "- CPU: " + item.PhoneTablet.Phone_Features.CPU + "<br />";
                    imageContent += "- GPU: " + item.PhoneTablet.Phone_Features.GPU + "<br />";
                    imageContent += "- Cảm biến: " + item.PhoneTablet.Phone_Features.Sensors + "<br />";
                    imageContent += "- Tin nhắn: " + item.PhoneTablet.Phone_Features.Messaging + "<br />";
                    imageContent += "- Trình duyệt: " + item.PhoneTablet.Phone_Features.Browser + "<br />";
                    imageContent += "- FM Radio: " + item.PhoneTablet.Phone_Features.Radio + "<br />";
                    imageContent += "- GPS: " + item.PhoneTablet.Phone_Features.GPS + "<br />";
                    imageContent += "- Java: " + item.PhoneTablet.Phone_Features.Java + "<br />";
                    imageContent += "- Màu sắc: " + item.PhoneTablet.Phone_Features.Colors + "<br />";
                    imageContent += "- Các đặc tính khác: " + item.PhoneTablet.Phone_Features.Others + "<br />";
                }
                if (item.PhoneTablet.IsBatteryHighlighted)
                {
                    imageContent += "- Dung lượng pin: " + item.PhoneTablet.Phone_Battery.Model + "<br />";
                    imageContent += "- Thời gian chờ: " + item.PhoneTablet.Phone_Battery.StandBy + "<br />";
                    imageContent += "- Thời gian đàm thoại: " + item.PhoneTablet.Phone_Battery.TalkTime + "<br />";
                    imageContent += "- Thời gian chơi nhạc: " + item.PhoneTablet.Phone_Battery.MusicPlay + "<br />";
                }
                if (item.PhoneTablet.IsMiscHighlighted)
                {
                }
                if (item.PhoneTablet.IsTestsHighlighted)
                {
                }
                imageContent += "</div>";
            }
        }
        @if (item.Category.Name.Equals("ĐIỆN THOẠI DI ĐỘNG")) // Smartphone
        {
            <a href="@Url.Content("~/Product/Smartphone/" + item.ProductID)">@Html.Encode(item.Name)</a>
            <br />
            <br />
            if (item.IsNew)
            {
                if (item.IsHighlighted)
                {
                    <a class="new-product" href="@Url.Content("~/Product/Smartphone/" + item.ProductID)"><img src="@Url.Content("~/Images/Products/Smartphones/" + item.ProductImage)" alt="" width="70" height="92" class="tooltip" title="@imageContent"/></a>
                }
                else
                {
                    <a class="new-product" href="@Url.Content("~/Product/Smartphone/" + item.ProductID)"><img src="@Url.Content("~/Images/Products/Smartphones/" + item.ProductImage)" alt="" width="70" height="92" /></a>
                }
            }
            else
            {
                if (item.IsHighlighted)
                {
                    <a href="@Url.Content("~/Product/Smartphone/" + item.ProductID)"><img src="@Url.Content("~/Images/Products/Smartphones/" + item.ProductImage)" alt="" width="70" height="92" class="tooltip" title="@imageContent"/></a>
                }
                else
                {
                    <a href="@Url.Content("~/Product/Smartphone/" + item.ProductID)"><img src="@Url.Content("~/Images/Products/Smartphones/" + item.ProductImage)" alt="" width="70" height="92" /></a>
                }
            }
            <br />
        }
        else if (item.Category.Name.Equals("MÁY TÍNH BẢNG"))
        {
            <a href="@Url.Content("~/Product/Tablet/" + item.ProductID)">@Html.Encode(item.Name)</a>
            <br />
            <br />
            if (item.IsNew)
            {
                if (item.IsHighlighted)
                {
                    <a class="new-product" href="@Url.Content("~/Product/Tablet/" + item.ProductID)"><img src="@Url.Content("~/Images/Products/Tablets/" + item.ProductImage)" alt="" width="70" height="92" class="tooltip" title="@imageContent"/></a>
                }
                else
                {
                    <a class="new-product" href="@Url.Content("~/Product/Tablet/" + item.ProductID)"><img src="@Url.Content("~/Images/Products/Tablets/" + item.ProductImage)" alt="" width="70" height="92" /></a>
                }
            }
            else
            {
                if (item.IsHighlighted)
                {
                    <a href="@Url.Content("~/Product/Tablet/" + item.ProductID)"><img src="@Url.Content("~/Images/Products/Tablets/" + item.ProductImage)" alt="" width="70" height="92" class="tooltip" title="@imageContent"/></a>
                }
                else
                {
                    <a href="@Url.Content("~/Product/Tablet/" + item.ProductID)"><img src="@Url.Content("~/Images/Products/Tablets/" + item.ProductImage)" alt="" width="70" height="92" /></a>
                }
            }
            <br />
        }
        <p>
            @if (!item.IsPromotional)
            {
                <strong>Giá: <span>@String.Format("{0:C0}", item.RetailPrice)</span></strong>
            }
            else
            {
                <strong>Giá cũ: <span class="old-price">@String.Format("{0:C0}", item.RetailPrice)</span></strong>
                <br />
                int newPrice = (int)item.RetailPrice * (100 - (int)item.Promotions.Last(p => p.ProductID == item.ProductID).Percentage) / 100;
                <strong>Giá mới: <span>@String.Format("{0:C0}", newPrice)</span></strong>
            }
        </p>
        @Html.ActionLink("Đặt hàng", "AddToCart", "ShoppingCart", new { id = item.ProductID }, new { @class = "add-to-cart" })
        @if (item.Category.Name.Equals("ĐIỆN THOẠI DI ĐỘNG"))
        {
            @Html.ActionLink("Chi tiết", "Smartphone", "Product", new { id = item.ProductID }, new { @class = "details" })
        }
        else if (item.Category.Name.Equals("MÁY TÍNH BẢNG"))
        {
            @Html.ActionLink("Chi tiết", "Tablet", "Product", new { id = item.ProductID }, new { @class = "details" })
        }
    </div>
}
@{
    string controller = @Html.ViewContext.RouteData.GetRequiredString("controller");
    string action = @Html.ViewContext.RouteData.GetRequiredString("action");
}
@Html.PagedListPager((IPagedList)ViewBag.OnePageOfProducts, page => Url.Action(action, controller, new { page }), PagedListRenderOptions.ClassicPlusFirstAndLast)